<!DOCTYPE html><html lang="cn" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Docker容器 | 碧蓝幻想</title><meta name="author" content="阿尔托莉雅"><meta name="copyright" content="阿尔托莉雅"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1.Docker概述:1.docker的概念： Docker是一个开源的应用容器引擎  Docker是一个用于开发，交付和运行应用程序的开放平台   诞生于2013年初，基于Go语言实现，dotCloud公司出品（后改名为Docker Inc）  Docker可以让开发者打包他们的应用以及依赖包到一个轻量级，可移植的容器中，然后发布到任何流行的Linux机器上  可以将程序及其依赖、运行环境一起打">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker容器">
<meta property="og:url" content="http://example.com/2023/03/13/3.linux/B1.Docker%E5%AE%B9%E5%99%A8/index.html">
<meta property="og:site_name" content="碧蓝幻想">
<meta property="og:description" content="1.Docker概述:1.docker的概念： Docker是一个开源的应用容器引擎  Docker是一个用于开发，交付和运行应用程序的开放平台   诞生于2013年初，基于Go语言实现，dotCloud公司出品（后改名为Docker Inc）  Docker可以让开发者打包他们的应用以及依赖包到一个轻量级，可移植的容器中，然后发布到任何流行的Linux机器上  可以将程序及其依赖、运行环境一起打">
<meta property="og:locale">
<meta property="og:image" content="http://example.com/images/Otherwallpaper/avatar.png">
<meta property="article:published_time" content="2023-03-13T12:32:23.838Z">
<meta property="article:modified_time" content="2023-03-13T12:48:16.593Z">
<meta property="article:author" content="阿尔托莉雅">
<meta property="article:tag" content="Linux">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/images/Otherwallpaper/avatar.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2023/03/13/3.linux/B1.Docker%E5%AE%B9%E5%99%A8/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Docker容器',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-03-13 20:48:16'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/images/Otherwallpaper/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archive/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/images/"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/video/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/images/PCwallpaper/backgroud2.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="碧蓝幻想"><span class="site-name">碧蓝幻想</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archive/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/images/"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/video/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Docker容器</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-03-13T12:32:23.838Z" title="Created 2023-03-13 20:32:23">2023-03-13</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-03-13T12:48:16.593Z" title="Updated 2023-03-13 20:48:16">2023-03-13</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Linux/">Linux</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Docker容器"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="1-Docker概述"><a href="#1-Docker概述" class="headerlink" title="1.Docker概述:"></a>1.Docker概述:</h2><h3 id="1-docker的概念："><a href="#1-docker的概念：" class="headerlink" title="1.docker的概念："></a>1.docker的概念：</h3><ol>
<li><p>Docker是一个<strong>开源的应用容器引擎</strong></p>
</li>
<li><p>Docker是一个用于开发，交付和运行应用程序的开放平台</p>
</li>
<li></li>
<li><p>诞生于2013年初，基于Go语言实现，dotCloud公司出品（后改名为Docker Inc）</p>
</li>
<li><p>Docker可以让开发者打包他们的应用以及依赖包到一个轻量级，可移植的容器中，然后发布到任何流行的Linux机器上</p>
</li>
<li><p>可以将<strong>程序及其依赖、运行环境一起打包为一个镜像</strong>，可以迁移到任意Linux操作系统</p>
</li>
<li><p>容器时完全使用<strong>沙箱机制</strong>，相互隔离</p>
</li>
<li><p>容器性能开销极低</p>
</li>
<li><p>Docker从17.03版本之后分为CE（社区版）和EE（企业版）</p>
</li>
<li><p>总结：</p>
</li>
</ol>
<p>   docker是一种容器技术，解决软件跨环境迁移的问题</p>
<h3 id="2-Docker解决的问题："><a href="#2-Docker解决的问题：" class="headerlink" title="2.Docker解决的问题："></a>2.Docker解决的问题：</h3><ul>
<li>Docker如何解决依赖的兼容问题：<ul>
<li>将应用的Libs（函数库）、Deps（依赖）、配置与应用一起打包</li>
<li>将每个应用放到一个隔离容器去运行，避免互相干扰</li>
</ul>
</li>
<li>Docker如何解决不同系统环境的问题：<ul>
<li>Docker将<strong>用户程序</strong>与所需要调用的系统(比如Ubuntu**)函数库<strong>一起</strong>打包**</li>
<li>Docker运行到不同操作系统时，直接基于打包的库函数，<strong>借助</strong>于操作系统的<strong>Linux内核来运行</strong></li>
</ul>
</li>
<li>Docker如何解决大型项目依赖关系复杂，不同组件依赖的兼容性问题？<ul>
<li>Docker允许开发中将应用、依赖、函数库、配置一起打包，形成可移植镜像</li>
<li>Docker应用运行在容器中，使用沙箱机制，相互隔离</li>
</ul>
</li>
<li>Docker如何解决开发、测试、生产环境有差异的问题<ul>
<li>Docker镜像中包含完整运行环境，包括系统函数库，仅<strong>依赖系统的Linux内核</strong>，因此可以在任意Linux操作系统上运行</li>
</ul>
</li>
</ul>
<h3 id="3-DokcerHub："><a href="#3-DokcerHub：" class="headerlink" title="3.DokcerHub："></a>3.DokcerHub：</h3><ul>
<li>DockerHub是一个<strong>Docker镜像的托管平台</strong>。这样的平台称为Docker Registry</li>
</ul>
<h2 id="2-安装Docker："><a href="#2-安装Docker：" class="headerlink" title="2.安装Docker："></a>2.安装Docker：</h2><ul>
<li><p>如果之前安装过旧版本的Docker，可以使用下面命令卸载：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">yum remove docker \</span><br><span class="line">                  docker-client \</span><br><span class="line">                  docker-client-latest \</span><br><span class="line">                  docker-common \</span><br><span class="line">                  docker-latest \</span><br><span class="line">                  docker-latest-logrotate \</span><br><span class="line">                  docker-logrotate \</span><br><span class="line">                  docker-selinux \</span><br><span class="line">                  docker-engine-selinux \</span><br><span class="line">                  docker-engine \</span><br><span class="line">                  docker-ce</span><br></pre></td></tr></table></figure>
</li>
<li><p>首先需要大家虚拟机联网，安装yum工具</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum install -y yum-utils \</span><br><span class="line">           device-mapper-persistent-data \</span><br><span class="line">           lvm2 --skip-broken</span><br></pre></td></tr></table></figure>
</li>
<li><p>添加docker镜像到本地：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">设置docker镜像源</span></span><br><span class="line">yum-config-manager \</span><br><span class="line">    --add-repo \</span><br><span class="line">    https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</span><br><span class="line">    </span><br><span class="line">sed -i &#x27;s/download.docker.com/mirrors.aliyun.com\/docker-ce/g&#x27; /etc/yum.repos.d/docker-ce.repo</span><br></pre></td></tr></table></figure>
</li>
<li><p>然后输入命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y docker-ce</span><br></pre></td></tr></table></figure>
</li>
<li><p>如发生报错：</p>
<p><img src="https://img-blog.csdnimg.cn/04a2f5ecf86d4fc8866fe7ac26393cbd.png" alt="img"></p>
</li>
<li><p>解决方案：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum erase podman buildan</span><br><span class="line"></span><br><span class="line">yum install -y docker-ce --allowerasing</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看是否安装成功：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker -v</span><br></pre></td></tr></table></figure>
</li>
<li><p>重启docker服务：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart docker</span><br></pre></td></tr></table></figure>
</li>
<li><p>镜像加速：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://cr.console.aliyun.com/cn-wulanchabu/instances/mirrors</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="3-Docker架构"><a href="#3-Docker架构" class="headerlink" title="3.Docker架构"></a>3.Docker架构</h2><ul>
<li><p>图示：</p>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230311180220664.png" alt="image-20230311180220664"></p>
</li>
<li><p>Docker是一个<strong>CS架构</strong>的程序，由两部分组成：</p>
<ul>
<li><p><strong>服务端</strong>（server）：Docker守护进程，负责处理Docker指令，管理镜像，容器等</p>
</li>
<li><p><strong>客户端</strong>(client)：通过命令或RestAPI向Docker服务端发送指令。可以在本地或远程向服务端发送指令</p>
</li>
</ul>
</li>
<li><p>描述：</p>
<ul>
<li><strong>镜像（image）</strong>：<ul>
<li><p>Docker将应用程序及其所需的依赖，函数库，环境，配置等文件打包在一起</p>
</li>
<li><p>是一个文件系统</p>
</li>
<li><p>相当于<strong>Class类</strong></p>
</li>
<li><p><strong>容器（Container）</strong>：</p>
<ul>
<li><p>镜像中的应用程序运行后形成的进程就是容器，只是Docker会给容器做隔离，对外不可见</p>
</li>
<li><p>相当于Example<strong>实例</strong>（根据类创建出来的对象）</p>
</li>
</ul>
</li>
<li><p><strong>仓库</strong>：</p>
<ul>
<li>仓库可看成一个代码控制中心，用来保存镜像</li>
<li>分类：远程仓库，私有仓库</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="4-docker命令："><a href="#4-docker命令：" class="headerlink" title="4.docker命令："></a>4.docker命令：</h2><h3 id="1-操作进程命令："><a href="#1-操作进程命令：" class="headerlink" title="1.操作进程命令："></a>1.操作进程命令：</h3><table>
<thead>
<tr>
<th>命令</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>systemctl start docker</td>
<td>启动docker服务</td>
</tr>
<tr>
<td>systemctl stop docker</td>
<td>停止docker服务</td>
</tr>
<tr>
<td>systemctl restart docker</td>
<td>重启docker服务</td>
</tr>
<tr>
<td>systemctl status docker</td>
<td>查看docker服务状态</td>
</tr>
<tr>
<td>systemctl enable docker</td>
<td>开机启动docker服务</td>
</tr>
<tr>
<td>systemctl disable docker</td>
<td>关闭开机启动docker服务</td>
</tr>
</tbody></table>
<h3 id="2-查看帮助："><a href="#2-查看帮助：" class="headerlink" title="2.查看帮助："></a>2.查看帮助：</h3><table>
<thead>
<tr>
<th>命令</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>docker –help</td>
<td>查看docker所有帮助</td>
</tr>
<tr>
<td>docker [命令] –help</td>
<td>查看docker相关命令的帮助</td>
</tr>
</tbody></table>
<h3 id="3-操作镜像命令："><a href="#3-操作镜像命令：" class="headerlink" title="3.操作镜像命令："></a>3.操作镜像命令：</h3><ul>
<li><p>查看镜像：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>q</td>
<td>查看本地的镜像文件的id</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker images        # 查看本地的镜像文件</span><br><span class="line">docker images -q     # 查看本地的镜像文件的id</span><br></pre></td></tr></table></figure>
</li>
<li><p>搜索镜像：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker search 镜像名称</span><br></pre></td></tr></table></figure>
</li>
<li><p>拉取镜像：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker pull 镜像名称            # 不写版本号：（下载最新的）</span><br><span class="line">docker pull 镜像名称:版本号     # 写版本号：  （docker官方搜索寻找版本号）</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除镜像：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker rmi 镜像id                 #  通过image id删除</span><br><span class="line">docker rmi 镜像名称:版本号         # 通过镜像名+版本号删除</span><br><span class="line">docker rmi $(docker images -q)    # 删除所有的镜像</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="4-操作容器命令："><a href="#4-操作容器命令：" class="headerlink" title="4.操作容器命令："></a>4.操作容器命令：</h3><ul>
<li><p>查看容器：   </p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>a</td>
<td>查看所有状态的容器</td>
</tr>
<tr>
<td>p</td>
<td>查看所有容器的id</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker ps          # 查看正在运行的容器</span><br><span class="line">docker ps -a       # 查看所有状态的容器</span><br><span class="line">docker ps -aq      # 查看所有容器的id</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建容器：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>i</td>
<td>表示容器运行</td>
</tr>
<tr>
<td>t</td>
<td>表示给容器分配伪终端</td>
</tr>
<tr>
<td>it</td>
<td>表示容器创建后自动进入容器中，退出容器自动关闭</td>
</tr>
<tr>
<td>d</td>
<td>表示容器后台创建；需要命令进入容器；退出不会自动关闭容器</td>
</tr>
<tr>
<td>id</td>
<td>创建的容器一般称为交互式容器；id创建的容器一般称为守护式容器</td>
</tr>
<tr>
<td>–name&#x3D;</td>
<td>指定所创建容器的名称</td>
</tr>
<tr>
<td>-p</td>
<td>将容器的 80端口映射到宿主机的 80 端口</td>
</tr>
<tr>
<td>v</td>
<td>挂载目录</td>
</tr>
</tbody></table>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker run -it --name=容器名称 镜像名:版本号 /bin/bash           # 创建容器+伪终端</span><br><span class="line">docker run -id --name==容器名称 镜像名:版本号 /bin/bash          # 创建容器+后台创建</span><br><span class="line">docker run ... -v 宿主机目录（数据卷名）:容器内目录 镜像名称:7     # 创建容器+伪终端+挂载目录</span><br></pre></td></tr></table></figure>
</li>
<li><p>进入容器：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>i</td>
<td>表示一直运行（除非关闭客户端）</td>
</tr>
<tr>
<td>t</td>
<td>表示给容器分配伪终端</td>
</tr>
</tbody></table>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it 容器名 定义的指令</span><br></pre></td></tr></table></figure>
</li>
<li><p>退出容器：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">exit</span><br></pre></td></tr></table></figure>
</li>
<li><p>启动容器：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker start 容器名称</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改容器：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker update --restart always 容器ID   # 如果容器已经创建，可以通过以下方式更新重启策略（开机自启容器）</span><br></pre></td></tr></table></figure>
</li>
<li><p>停止容器：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker stop 容器名称</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除容器：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker rm 容器名称           # 根据容器名称删除容器</span><br><span class="line">docker rm 容器id            # 根据id删除容器</span><br><span class="line">docker rm 容器名称:版本号    # 根据名称+（版本号）删除容器</span><br><span class="line">docker rm -f 容器名称       # 强制删除容器</span><br><span class="line">docker rm docker ps -aq   # 删除所有容器</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看容器信息：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker inspect 容器名称</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看容器日志：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker logs 容器名         # 根据容器名查看日志</span><br><span class="line">docker logs -f 容器名      # 根据容器名查看日志+跟踪日志</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="5-操作数据卷："><a href="#5-操作数据卷：" class="headerlink" title="5.操作数据卷："></a>5.操作数据卷：</h3><ul>
<li><p>创建数据卷：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#自动创建在/var/lib/docker/volumes目录下</span><br><span class="line">docker volume create 数据卷名</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看数据卷：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker volume ls                  # 查看所有的数据卷名称</span><br><span class="line">docker volume inspect 数据卷名称   # 查看指定数据卷的位置</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除数据卷</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker volume prune            # 删除所有未使用的数据卷</span><br><span class="line">docker volume rm 数据卷名称     # 删除指定的数据卷</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="5-Docker-应用部署"><a href="#5-Docker-应用部署" class="headerlink" title="5.Docker 应用部署"></a>5.Docker 应用部署</h2><h3 id="1-部署MySQL"><a href="#1-部署MySQL" class="headerlink" title="1.部署MySQL"></a>1.部署MySQL</h3><ol>
<li>搜索mysql镜像</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker search mysql</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>拉取mysql镜像</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull mysql:5.6</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>创建容器，设置端口映射、目录映射</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在/root目录下创建mysql目录用于存储mysql数据信息</span></span><br><span class="line">mkdir ~/mysql</span><br><span class="line">cd ~/mysql</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">docker run -id \</span><br><span class="line">-p 3307:3306 \</span><br><span class="line">--name=c_mysql \</span><br><span class="line">-v $PWD/conf:/etc/mysql/conf.d \       </span><br><span class="line">-v $PWD/logs:/logs \</span><br><span class="line">-v $PWD/data:/var/lib/mysql \</span><br><span class="line">-e MYSQL_ROOT_PASSWORD=123456 \</span><br><span class="line">mysql:5.6</span><br></pre></td></tr></table></figure>

<ul>
<li>参数说明：<ul>
<li><strong>-p 3307:3306</strong>：将容器的 3306 端口映射到宿主机的 3307 端口。</li>
<li><strong>$PWD</strong>：为显示当前目录位置</li>
<li><strong>-v $PWD&#x2F;conf:&#x2F;etc&#x2F;mysql&#x2F;conf.d</strong>：将主机当前目录下的 conf&#x2F;my.cnf 挂载到容器的 &#x2F;etc&#x2F;mysql&#x2F;my.cnf。配置目录</li>
<li><strong>-v $PWD&#x2F;logs:&#x2F;logs</strong>：将主机当前目录下的 logs 目录挂载到容器的 &#x2F;logs。日志目录</li>
<li><strong>-v $PWD&#x2F;data:&#x2F;var&#x2F;lib&#x2F;mysql</strong> ：将主机当前目录下的data目录挂载到容器的 &#x2F;var&#x2F;lib&#x2F;mysql 。数据目录</li>
<li><strong>-e MYSQL_ROOT_PASSWORD&#x3D;123456：</strong>初始化 root 用户的密码。</li>
</ul>
</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">MYSQL8.0以后的版本需要需改加密规则</span></span><br><span class="line">GRANT ALL ON *.* TO &#x27;root&#x27;@&#x27;%&#x27;;      # 授权</span><br><span class="line">flush privileges;       # 刷新权限</span><br><span class="line">ALTER USER &#x27;root&#x27;@&#x27;localhost&#x27; IDENTIFIED BY &#x27;password&#x27; PASSWORD EXPIRE NEVER;      # 更改加密规则</span><br><span class="line">ALTER USER &#x27;root&#x27;@&#x27;%&#x27; IDENTIFIED WITH mysql_native_password BY &#x27;123456&#x27;;      # 更新root用户密码</span><br><span class="line">flush privileges;      # 刷新权限</span><br><span class="line">docker restart [容器名]</span><br></pre></td></tr></table></figure>



<ol start="4">
<li>进入容器，操作mysql</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec –it c_mysql /bin/bash</span><br></pre></td></tr></table></figure>

<ol start="5">
<li><p>使用外部机器连接容器中的mysql（<strong>密码：123456</strong>）</p>
<p><img src="C:\Users\user\AppData\Roaming\Typora\typora-user-images\image-20211206160946890.png" alt="image-20211206160946890"></p>
</li>
</ol>
<h3 id="2-部署Tomcat"><a href="#2-部署Tomcat" class="headerlink" title="2.部署Tomcat"></a>2.部署Tomcat</h3><ol>
<li>搜索tomcat镜像</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker search tomcat</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>拉取tomcat镜像</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull tomcat</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>创建容器，设置端口映射、目录映射</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在/root目录下创建tomcat目录用于存储tomcat数据信息</span></span><br><span class="line">mkdir ~/tomcat</span><br><span class="line">cd ~/tomcat</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker run -id --name=c_tomcat \</span><br><span class="line">-p 8080:8080 \</span><br><span class="line">-v $PWD:/usr/local/tomcat/webapps \</span><br><span class="line">tomcat </span><br></pre></td></tr></table></figure>

<ul>
<li><p>参数说明：</p>
<ul>
<li><p><strong>-p 8080:8080：</strong>将容器的8080端口映射到主机的8080端口</p>
<p><strong>-v $PWD:&#x2F;usr&#x2F;local&#x2F;tomcat&#x2F;webapps：</strong>将主机中当前目录挂载到容器的webapps</p>
</li>
</ul>
</li>
</ul>
<ol start="4">
<li>使用外部机器访问tomcat</li>
</ol>
<p><img src="D:\Typora笔记\4.西安欧鹏\3.linux\imgs\1573649804623.png" alt="1573649804623"></p>
<h3 id="3-部署Nginx"><a href="#3-部署Nginx" class="headerlink" title="3.部署Nginx"></a>3.部署Nginx</h3><ol>
<li>搜索nginx镜像</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker search nginx</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>拉取nginx镜像</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull nginx</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>创建容器，设置端口映射、目录映射</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在/root目录下创建nginx目录用于存储nginx数据信息</span></span><br><span class="line">mkdir ~/nginx</span><br><span class="line">cd ~/nginx</span><br><span class="line">mkdir conf</span><br></pre></td></tr></table></figure>

<p>返回上层目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd ..</span><br></pre></td></tr></table></figure>




<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">docker run -id --name=c_nginx \</span><br><span class="line">-p 80:80 \</span><br><span class="line">-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf \</span><br><span class="line">-v $PWD/logs:/var/log/nginx \</span><br><span class="line">-v $PWD/html:/usr/share/nginx/html \</span><br><span class="line">nginx</span><br></pre></td></tr></table></figure>

<ul>
<li>参数说明：<ul>
<li><strong>-p 80:80</strong>：将容器的 80端口映射到宿主机的 80 端口。</li>
<li><strong>-v $PWD&#x2F;conf&#x2F;nginx.conf:&#x2F;etc&#x2F;nginx&#x2F;nginx.conf</strong>：将主机当前目录下的 &#x2F;conf&#x2F;nginx.conf 挂载到容器的 :&#x2F;etc&#x2F;nginx&#x2F;nginx.conf。配置目录</li>
<li><strong>-v $PWD&#x2F;logs:&#x2F;var&#x2F;log&#x2F;nginx</strong>：将主机当前目录下的 logs 目录挂载到容器的&#x2F;var&#x2F;log&#x2F;nginx。日志目录</li>
</ul>
</li>
</ul>
<ol start="4">
<li>使用外部机器访问nginx</li>
</ol>
<p><img src="D:\Typora笔记\4.西安欧鹏\3.linux\imgs\1573652396669.png" alt="1573652396669"></p>
<h3 id="4-部署Redis"><a href="#4-部署Redis" class="headerlink" title="4.部署Redis"></a>4.部署Redis</h3><ol>
<li>搜索redis镜像</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker search redis</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>拉取redis镜像</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull redis:5.0</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>上传redis.conf配置文件</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">链接：https:<span class="comment">//pan.baidu.com/s/1hNZk4aXzlShhMFYcqLyKIQ </span></span><br><span class="line">提取码：abcd</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>创建容器，设置端口映射</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -id --name=c_redis -p 6379:6379 -v $PWD/data:/data -v $PWD/redis.conf:/etc/redis/redis.conf redis:6.2.4</span><br></pre></td></tr></table></figure>

<ol start="4">
<li>进入redis容器</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it c_redis /bin/bash</span><br></pre></td></tr></table></figure>

<ol start="5">
<li>启动redis客户端：</li>
</ol>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">redis-cli</span><br></pre></td></tr></table></figure>



<h2 id="6-搭建博客程序："><a href="#6-搭建博客程序：" class="headerlink" title="6.搭建博客程序："></a>6.搭建博客程序：</h2><h3 id="1-搭建halo："><a href="#1-搭建halo：" class="headerlink" title="1.搭建halo："></a>1.搭建halo：</h3><ul>
<li><p>安装JAVA：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo yum install java-11-openjdk -y</span><br><span class="line">java -version</span><br></pre></td></tr></table></figure>
</li>
<li><p>安装mysql：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">docker run -id \</span><br><span class="line">-p 3307:3306 \</span><br><span class="line">--name=b_mysql \</span><br><span class="line">-v $PWD/conf:/etc/mysql/mysql.conf.d \       </span><br><span class="line">-v $PWD/logs:/var/logs \</span><br><span class="line">-v $PWD/data:/var/lib/mysql \</span><br><span class="line">-e MYSQL_ROOT_PASSWORD=$Rui123456 \</span><br><span class="line">mysql:8.0.32</span><br></pre></td></tr></table></figure>
</li>
<li><p>安装halo：</p>
<ul>
<li><p>下载application.yaml模板：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mkdir ~/.halo &amp;&amp; cd ~/.halo</span><br><span class="line">wget https://dl.halo.run/config/application-template.yaml -O ./application.yaml</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改application.yaml配置文件：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">8090</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># Response data gzip.</span></span><br><span class="line">  <span class="attr">compression:</span></span><br><span class="line">    <span class="attr">enabled:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">datasource:</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># H2 database configuration.</span></span><br><span class="line">    <span class="comment"># driver-class-name: org.h2.Driver</span></span><br><span class="line">    <span class="comment">#url: jdbc:h2:file:~/.halo/db/halo</span></span><br><span class="line">    <span class="comment">#username: admin</span></span><br><span class="line">    <span class="comment">#password: 123456</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># MySQL database configuration.</span></span><br><span class="line">    <span class="attr">driver-class-name:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br><span class="line">    <span class="attr">url:</span> <span class="string">jdbc:mysql://8.130.17.95:3307/halodb?characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=Asia/Shanghai&amp;allowPublicKeyRetrieval=true</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">&#x27;@Qv110119&#x27;</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># H2 database console configuration.</span></span><br><span class="line">  <span class="comment">#h2:</span></span><br><span class="line">  <span class="comment">#  console:</span></span><br><span class="line">  <span class="comment">#    settings:</span></span><br><span class="line">  <span class="comment">#      web-allow-others: false</span></span><br><span class="line">  <span class="comment">#    path: /h2-console</span></span><br><span class="line">  <span class="comment">#    enabled: false</span></span><br><span class="line"></span><br><span class="line"><span class="attr">halo:</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># Your admin client path is https://your-domain/&#123;admin-path&#125;</span></span><br><span class="line">  <span class="attr">admin-path:</span> <span class="string">admin</span></span><br><span class="line"></span><br><span class="line">  <span class="comment"># memory or level</span></span><br><span class="line">  <span class="attr">cache:</span> <span class="string">memory</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>创建halo容器：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">docker</span> <span class="string">run</span> <span class="string">-it</span> <span class="string">-d</span> <span class="string">--name</span> <span class="string">halo</span> <span class="string">-p</span> <span class="number">8090</span><span class="string">:8090</span> <span class="string">-v</span> <span class="string">~/.halo:/root/.halo</span> <span class="string">--restart=unless-stopped</span> <span class="string">halohub/halo:1.6.0</span></span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="2-搭建hexo："><a href="#2-搭建hexo：" class="headerlink" title="2.搭建hexo："></a>2.搭建hexo：</h3><h2 id="7-Docker的网络："><a href="#7-Docker的网络：" class="headerlink" title="7.Docker的网络："></a>7.Docker的网络：</h2><h3 id="1-概念："><a href="#1-概念：" class="headerlink" title="1.概念："></a>1.概念：</h3><p>- </p>
<ul>
<li>作用：<ul>
<li>容器间的互联和通信以及端口映射</li>
<li>容器IP变动时候（容器内部网络可能发生变化），网络通信不受影响</li>
</ul>
</li>
<li>ifconfig中的docker0虚拟网卡<ul>
<li>负责宿主机和docker容器的通信</li>
<li>负责docker容器之间的通信</li>
</ul>
</li>
</ul>
<h3 id="2-基本命令："><a href="#2-基本命令：" class="headerlink" title="2.基本命令："></a>2.基本命令：</h3><ul>
<li><p>当你安装docker时，它会自动创建三个网络，可使用如下命令查看：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@zhanglin dockerfile]# docker network ls</span><br><span class="line">NETWORK ID     NAME      DRIVER    SCOPE</span><br><span class="line">31b01340df19   bridge    bridge    local</span><br><span class="line">84be79f83115   host      host      local</span><br><span class="line">b8f15339e0e3   none      null      local</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看网络命令帮助：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network --help</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建docker网络：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network create [网络名]</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看指定的docker网络：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network inspect [网络名]</span><br></pre></td></tr></table></figure>
</li>
<li><p>连接容器到一个网络中：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network connect</span><br></pre></td></tr></table></figure>
</li>
<li><p>断开网络中的一个网络</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network disconnect</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除指定的docker网络：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network rm [网络名]</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除所有不使用的docker网络：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network prune </span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="3-网络模式："><a href="#3-网络模式：" class="headerlink" title="3.网络模式："></a>3.网络模式：</h3><ul>
<li><p>bridge模式：</p>
<ul>
<li><p>概念：默认模式，为每一容器创建网卡，分配IP，并将容器连接到docker0</p>
</li>
<li><p>图示：</p>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230312161227047.png" alt="image-20230312161227047"></p>
</li>
</ul>
</li>
<li><p>host模式：</p>
<ul>
<li><p>容器不会虚拟出自己的网卡和IP，容器使用宿主机的IP和地址</p>
</li>
<li><p>图示：</p>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230312162334136.png" alt="image-20230312162334136"></p>
</li>
</ul>
</li>
<li><p>none模式：</p>
<ul>
<li><p>概念：容器拥有自己的Network Namespace，没有任何网络配置</p>
</li>
<li><p>图示：</p>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230312162847685.png" alt="image-20230312162847685"></p>
</li>
</ul>
</li>
<li><p>container模式：</p>
<ul>
<li><p>新创建的容器不会创建自己d额网卡和配置自己的IP，而是和一个指定的容器共享IP，端口范围</p>
</li>
<li><p>图示：</p>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230312163019822.png" alt="image-20230312163019822"></p>
</li>
</ul>
</li>
</ul>
<h2 id="8-DockerFile："><a href="#8-DockerFile：" class="headerlink" title="8.DockerFile："></a>8.DockerFile：</h2><h3 id="1-docker镜像原理："><a href="#1-docker镜像原理：" class="headerlink" title="1.docker镜像原理："></a>1.docker镜像原理：</h3><ul>
<li>Linux文件系统由两部分组成：<ul>
<li>boofs：包含bootloader（引导加载程序）和kernel（内核）</li>
<li>rootfs：root文件系统，如：&#x2F;dev，&#x2F;etc，&#x2F;bin等</li>
</ul>
</li>
<li>不同的发行版本，bootfs基本一样，rootfs不同</li>
<li>Docker镜像的<strong>本质是分层的文件系统</strong>，<strong>由特殊的文件系统叠加而成</strong></li>
<li>Docker镜像的组成：</li>
</ul>
<ol>
<li><strong>最底层</strong>的是<strong>bootfs</strong>（为宿主机的bootfs）</li>
<li>第二层为rootfs，也被称为基础镜像</li>
<li>再往上为其他镜像</li>
</ol>
<ul>
<li>说明：位于下方的镜像为父镜像，最低层的为<strong>基础镜像</strong></li>
<li><strong>只读镜像</strong>：可以<strong>复用</strong>的镜像（不可以修改）</li>
</ul>
<h3 id="2-镜像制作："><a href="#2-镜像制作：" class="headerlink" title="2.镜像制作："></a>2.镜像制作：</h3><ul>
<li><p>容器转为镜像：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker commit 容器id 镜像名称:版本号</span><br></pre></td></tr></table></figure>
</li>
<li><p>镜像转为压缩文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker save -o 压缩文件名 镜像名称:版本号     # o(output)</span><br></pre></td></tr></table></figure>
</li>
<li><p>将压缩文件转为镜像：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker load -i 压缩文件名                   # i(input)</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="3-Dockerfile的概念："><a href="#3-Dockerfile的概念：" class="headerlink" title="3.Dockerfile的概念："></a>3.Dockerfile的概念：</h3><ul>
<li>Docker是一个文本文件，文件中包含一条条指令</li>
<li><strong>每一行指令构建一层镜像</strong>，基于基础镜像，最终构建出一个新的镜像</li>
<li>作用：<ul>
<li>提供完全一致的开发环境</li>
<li>在部署时，可以实现应用的无缝链接</li>
</ul>
</li>
</ul>
<h3 id="4-Dockerfile的使用："><a href="#4-Dockerfile的使用：" class="headerlink" title="4.Dockerfile的使用："></a>4.Dockerfile的使用：</h3><ul>
<li><p>dockerfile的关键字：</p>
<table>
<thead>
<tr>
<th>关键字</th>
<th>作用</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>from</td>
<td>指定父镜像</td>
<td>指定dockerfile基于那个image构建</td>
</tr>
<tr>
<td>maintainer</td>
<td>作者信息</td>
<td>用来标注这个dockerfile是谁写的</td>
</tr>
<tr>
<td>label</td>
<td>标签</td>
<td>可以代替maintainer</td>
</tr>
<tr>
<td>run</td>
<td>容器创建命令</td>
<td>容器创建时执行</td>
</tr>
<tr>
<td>cmd</td>
<td>容器启动命令</td>
<td>容器启动时执行，与挂载参数v冲突</td>
</tr>
<tr>
<td>entrypoint</td>
<td>入口</td>
<td>容器启动时执行，与挂载参数v冲突</td>
</tr>
<tr>
<td>copy</td>
<td>复制文件</td>
<td></td>
</tr>
<tr>
<td>add</td>
<td>添加文件</td>
<td></td>
</tr>
<tr>
<td>env</td>
<td>环境变量</td>
<td></td>
</tr>
<tr>
<td>arg</td>
<td>构建参数</td>
<td></td>
</tr>
<tr>
<td>volume</td>
<td>构建数据卷</td>
<td></td>
</tr>
<tr>
<td>expose</td>
<td>暴露端口</td>
<td>容器暴露在外的端口，需要映射</td>
</tr>
<tr>
<td>workdir</td>
<td>工作目录</td>
<td>进入容器时的默认路径</td>
</tr>
<tr>
<td>user</td>
<td>指定执行用户</td>
<td></td>
</tr>
<tr>
<td>build</td>
<td>构建镜像</td>
<td></td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">FROM java:8         # 指定父镜像</span><br><span class="line">MAINTAINER qv123&lt;qv123@qq.com&gt;      # 注释</span><br><span class="line">ADD springboot.jar ....     # 添加文件</span><br><span class="line">CMD jar -jar springboot.jar      # 启动容器时执行的命令</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">FROM centos:7                    # 指定父镜像</span><br><span class="line">MAINTAINER qv123&lt;qv123@qq.com&gt;      # 注释</span><br><span class="line">RUN yum install -y vim           # 启动容器时执行的命令</span><br><span class="line">WORKDIR /usr/local               # 指定默认工作目录</span><br><span class="line">CMD /bin/bash                    # 启动容器时执行的命令</span><br></pre></td></tr></table></figure>
</li>
<li><p>构建镜像：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker build -f dockerfile文件路径 -t 镜像名称:版本 . </span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="9-Docker服务编排："><a href="#9-Docker服务编排：" class="headerlink" title="9.Docker服务编排："></a>9.Docker服务编排：</h2><h3 id="1-服务编排概念："><a href="#1-服务编排概念：" class="headerlink" title="1.服务编排概念："></a>1.服务编排概念：</h3><ul>
<li>按照一定的业务规则批量管理容器</li>
</ul>
<h3 id="2-Docker-Compose概述"><a href="#2-Docker-Compose概述" class="headerlink" title="2.Docker Compose概述:"></a>2.Docker Compose概述:</h3><ul>
<li>Docker Compose是一个编排多容器分布式部署的工具</li>
<li>提供命令集管理容器化应用d额完整开发周期，包括服务构建，启动和停止</li>
<li>使用步骤<ol>
<li>使用Dockerfile定义运行环境镜像</li>
<li>使用docker-compose.yml定义组成应用的各种服务</li>
<li>运行docker-compose up启动应用</li>
</ol>
</li>
</ul>
<h3 id="3-安装和卸载Docker-Compose"><a href="#3-安装和卸载Docker-Compose" class="headerlink" title="3.安装和卸载Docker Compose:"></a>3.安装和卸载Docker Compose:</h3><ul>
<li><p>二进制方式：</p>
<ul>
<li><p>安装：</p>
<ul>
<li><p>curl下载</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose</span><br></pre></td></tr></table></figure>
</li>
<li><p>设置文件可执行权限：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod u+x /usr/local/bin/docker-compose</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看compose版本信息：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker-compose -version</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>卸载：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rm /usr/local/bin/docker-compose</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="4-Docker-compose的使用："><a href="#4-Docker-compose的使用：" class="headerlink" title="4.Docker-compose的使用："></a>4.Docker-compose的使用：</h3><ul>
<li><p>创建Docker-compose文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim docker-compose.yml    # 必须叫此名</span><br></pre></td></tr></table></figure>
</li>
<li><p>编写docker-compose.yml</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">version:</span> <span class="string">&#x27;3&#x27;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">nginx:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">nginx</span></span><br><span class="line">    <span class="attr">ports:</span> <span class="number">80</span><span class="string">:80</span></span><br><span class="line">    <span class="attr">links:</span> <span class="string">springboot</span></span><br><span class="line">    <span class="attr">volumes:</span> </span><br><span class="line">      <span class="bullet">-</span> <span class="string">./nginx/conf.d:/etc/nginx/conf.d</span>    <span class="comment"># 创建外部目录</span></span><br><span class="line">  <span class="attr">springboot:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">springboot</span></span><br><span class="line">    <span class="attr">expose:</span> <span class="string">&quot;8080&quot;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在本目录下使用docker compose启动容器</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker-compose up</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="10-Docker的私有仓库："><a href="#10-Docker的私有仓库：" class="headerlink" title="10.Docker的私有仓库："></a>10.Docker的私有仓库：</h2><h3 id="1-搭建私有仓库："><a href="#1-搭建私有仓库：" class="headerlink" title="1.搭建私有仓库："></a>1.搭建私有仓库：</h3><ul>
<li><p>拉取私有仓库镜像：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull registry</span><br></pre></td></tr></table></figure>
</li>
<li><p>启动私有仓库容器：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -id --name=registry -p 5000:5000 registry</span><br></pre></td></tr></table></figure>
</li>
<li><p>检测是否搭建成功：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">http://localhost:5000/v2/_catelog</span><br><span class="line"># 成功显示：&#123;&quot;repositories&quot;:[]&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改daemon.json，添加键值对：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/docker/daemon.json</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">添加内容</span></span><br><span class="line">&#123;&quot;insecure-registries&quot;:[&quot;IP地址:5000&quot;]&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>重启docker服务，重启私有仓库容器</p>
</li>
</ul>
<h3 id="2-上传镜像至私有仓库："><a href="#2-上传镜像至私有仓库：" class="headerlink" title="2.上传镜像至私有仓库："></a>2.上传镜像至私有仓库：</h3><ul>
<li><p>标记镜像为私有仓库的镜像：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker tag centos:7 IP地址:5000/centos:7</span><br></pre></td></tr></table></figure>
</li>
<li><p>上传标记的镜像：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker push IP地址:5000/centos:7</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="3-从私有仓库拉取镜像："><a href="#3-从私有仓库拉取镜像：" class="headerlink" title="3.从私有仓库拉取镜像："></a>3.从私有仓库拉取镜像：</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull IP地址:5000/centos:7</span><br></pre></td></tr></table></figure>





</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="http://example.com">阿尔托莉雅</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://example.com/2023/03/13/3.linux/B1.Docker%E5%AE%B9%E5%99%A8/">http://example.com/2023/03/13/3.linux/B1.Docker%E5%AE%B9%E5%99%A8/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Linux/">Linux</a></div><div class="post_share"><div class="social-share" data-image="/images/Otherwallpaper/avatar.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/03/13/3.linux/C1.git%E5%B7%A5%E5%85%B7/" title="git工具"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">git工具</div></div></a></div><div class="next-post pull-right"><a href="/2023/03/13/3.linux/A4.Shell%E8%84%9A%E6%9C%AC/" title="Shell脚本"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">Shell脚本</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>Related Articles</span></div><div class="relatedPosts-list"><div><a href="/2023/03/13/3.linux/A1.linux%E5%9F%BA%E7%A1%80/" title="Linux基础"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Linux基础</div></div></a></div><div><a href="/2023/03/13/3.linux/A2.Linux%E5%88%9D%E7%BA%A7%E5%91%BD%E4%BB%A4/" title="Linux初级命令"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Linux初级命令</div></div></a></div><div><a href="/2023/03/13/3.linux/A3.Linux%E4%B8%AD%E7%BA%A7%E5%91%BD%E4%BB%A4/" title="Linux中级命令"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Linux中级命令</div></div></a></div><div><a href="/2023/03/13/3.linux/A4.Shell%E8%84%9A%E6%9C%AC/" title="Shell脚本"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Shell脚本</div></div></a></div><div><a href="/2023/03/13/3.linux/C1.git%E5%B7%A5%E5%85%B7/" title="git工具"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">git工具</div></div></a></div><div><a href="/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/" title="Ansible基础"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Ansible基础</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/images/Otherwallpaper/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">阿尔托莉雅</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://toscode.gitee.com/blue-fantasy" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="/1095322098@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-Docker%E6%A6%82%E8%BF%B0"><span class="toc-number">1.</span> <span class="toc-text">1.Docker概述:</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-docker%E7%9A%84%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">1.1.</span> <span class="toc-text">1.docker的概念：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-Docker%E8%A7%A3%E5%86%B3%E7%9A%84%E9%97%AE%E9%A2%98%EF%BC%9A"><span class="toc-number">1.2.</span> <span class="toc-text">2.Docker解决的问题：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-DokcerHub%EF%BC%9A"><span class="toc-number">1.3.</span> <span class="toc-text">3.DokcerHub：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E5%AE%89%E8%A3%85Docker%EF%BC%9A"><span class="toc-number">2.</span> <span class="toc-text">2.安装Docker：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-Docker%E6%9E%B6%E6%9E%84"><span class="toc-number">3.</span> <span class="toc-text">3.Docker架构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-docker%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.</span> <span class="toc-text">4.docker命令：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%93%8D%E4%BD%9C%E8%BF%9B%E7%A8%8B%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.1.</span> <span class="toc-text">1.操作进程命令：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E6%9F%A5%E7%9C%8B%E5%B8%AE%E5%8A%A9%EF%BC%9A"><span class="toc-number">4.2.</span> <span class="toc-text">2.查看帮助：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E6%93%8D%E4%BD%9C%E9%95%9C%E5%83%8F%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.3.</span> <span class="toc-text">3.操作镜像命令：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E6%93%8D%E4%BD%9C%E5%AE%B9%E5%99%A8%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">4.4.</span> <span class="toc-text">4.操作容器命令：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%8D%B7%EF%BC%9A"><span class="toc-number">4.5.</span> <span class="toc-text">5.操作数据卷：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-Docker-%E5%BA%94%E7%94%A8%E9%83%A8%E7%BD%B2"><span class="toc-number">5.</span> <span class="toc-text">5.Docker 应用部署</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E9%83%A8%E7%BD%B2MySQL"><span class="toc-number">5.1.</span> <span class="toc-text">1.部署MySQL</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E9%83%A8%E7%BD%B2Tomcat"><span class="toc-number">5.2.</span> <span class="toc-text">2.部署Tomcat</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E9%83%A8%E7%BD%B2Nginx"><span class="toc-number">5.3.</span> <span class="toc-text">3.部署Nginx</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E9%83%A8%E7%BD%B2Redis"><span class="toc-number">5.4.</span> <span class="toc-text">4.部署Redis</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E7%A8%8B%E5%BA%8F%EF%BC%9A"><span class="toc-number">6.</span> <span class="toc-text">6.搭建博客程序：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%90%AD%E5%BB%BAhalo%EF%BC%9A"><span class="toc-number">6.1.</span> <span class="toc-text">1.搭建halo：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E6%90%AD%E5%BB%BAhexo%EF%BC%9A"><span class="toc-number">6.2.</span> <span class="toc-text">2.搭建hexo：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-Docker%E7%9A%84%E7%BD%91%E7%BB%9C%EF%BC%9A"><span class="toc-number">7.</span> <span class="toc-text">7.Docker的网络：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">7.1.</span> <span class="toc-text">1.概念：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%9F%BA%E6%9C%AC%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">7.2.</span> <span class="toc-text">2.基本命令：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%BC%8F%EF%BC%9A"><span class="toc-number">7.3.</span> <span class="toc-text">3.网络模式：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-DockerFile%EF%BC%9A"><span class="toc-number">8.</span> <span class="toc-text">8.DockerFile：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-docker%E9%95%9C%E5%83%8F%E5%8E%9F%E7%90%86%EF%BC%9A"><span class="toc-number">8.1.</span> <span class="toc-text">1.docker镜像原理：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E9%95%9C%E5%83%8F%E5%88%B6%E4%BD%9C%EF%BC%9A"><span class="toc-number">8.2.</span> <span class="toc-text">2.镜像制作：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-Dockerfile%E7%9A%84%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">8.3.</span> <span class="toc-text">3.Dockerfile的概念：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-Dockerfile%E7%9A%84%E4%BD%BF%E7%94%A8%EF%BC%9A"><span class="toc-number">8.4.</span> <span class="toc-text">4.Dockerfile的使用：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9-Docker%E6%9C%8D%E5%8A%A1%E7%BC%96%E6%8E%92%EF%BC%9A"><span class="toc-number">9.</span> <span class="toc-text">9.Docker服务编排：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%9C%8D%E5%8A%A1%E7%BC%96%E6%8E%92%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">9.1.</span> <span class="toc-text">1.服务编排概念：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-Docker-Compose%E6%A6%82%E8%BF%B0"><span class="toc-number">9.2.</span> <span class="toc-text">2.Docker Compose概述:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E5%AE%89%E8%A3%85%E5%92%8C%E5%8D%B8%E8%BD%BDDocker-Compose"><span class="toc-number">9.3.</span> <span class="toc-text">3.安装和卸载Docker Compose:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-Docker-compose%E7%9A%84%E4%BD%BF%E7%94%A8%EF%BC%9A"><span class="toc-number">9.4.</span> <span class="toc-text">4.Docker-compose的使用：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#10-Docker%E7%9A%84%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93%EF%BC%9A"><span class="toc-number">10.</span> <span class="toc-text">10.Docker的私有仓库：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%90%AD%E5%BB%BA%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93%EF%BC%9A"><span class="toc-number">10.1.</span> <span class="toc-text">1.搭建私有仓库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E4%B8%8A%E4%BC%A0%E9%95%9C%E5%83%8F%E8%87%B3%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93%EF%BC%9A"><span class="toc-number">10.2.</span> <span class="toc-text">2.上传镜像至私有仓库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E4%BB%8E%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93%E6%8B%89%E5%8F%96%E9%95%9C%E5%83%8F%EF%BC%9A"><span class="toc-number">10.3.</span> <span class="toc-text">3.从私有仓库拉取镜像：</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/B3.NoSQL%E6%95%B0%E6%8D%AE%E5%BA%93%20-%20MongDB/" title="NoSQL篇-MongDB数据库">NoSQL篇-MongDB数据库</a><time datetime="2023-03-13T12:32:38.445Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/B2.NoSQL%E6%95%B0%E6%8D%AE%E5%BA%93%20-%20Redis/" title="NoSQL篇-Redis数据库">NoSQL篇-Redis数据库</a><time datetime="2023-03-13T12:32:38.441Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/A1.MySQL-%E6%AC%A7%E9%B9%8F%E7%AF%87/" title="SQL篇-MySQL数据库">SQL篇-MySQL数据库</a><time datetime="2023-03-13T12:32:38.437Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/3.linux/D2.Ansible%E5%89%A7%E6%9C%AC/" title="Ansible">Ansible</a><time datetime="2023-03-13T12:32:23.866Z" title="Created 2023-03-13 20:32:23">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/" title="Ansible基础">Ansible基础</a><time datetime="2023-03-13T12:32:23.861Z" title="Created 2023-03-13 20:32:23">2023-03-13</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 阿尔托莉雅</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Toggle Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>